import pluginConfig from '../src/pluginConfig';
import vueUtils from '../vue.utils.ts';

const htmlPlugin = () => {
  const runEnvType = vueUtils('envType', '3', 'string');
  const runType = vueUtils('type', '', 'string');
  const appHTML = runEnvType === '3' ? 'proxyDev' : runEnvType  === '2' ? 'proxyFz' : 'proxyProd';
  const injectApp = runType === 'dev' ? [
  {
    tag: 'script',
    attrs: {
      src: `/${appHTML}/localWww/map/map.min.js`,
    },
    injectTo: 'body',
  },
  {
    tag: 'script',
    attrs: {
      src: `/${appHTML}/localWww/map/axios.min.js`,
    },
    injectTo: 'body',
  }] : [{
    tag: 'script',
    attrs: {
      src: `/${appHTML}/index.js`
    },
    injectTo: 'body',
  }];

  return {
    name: 'html-transform',
    transformIndexHtml() {
      return [
        ...injectApp,
        {
          tag: 'script',
          attrs: {
            id: pluginConfig.appId
          },
          injectTo: 'body'
        }
      ]
    }
  };
};

export default htmlPlugin;
